<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 计算两个数的和
    function calculateSum() {
      while (true) {
        let num1 = parseFloat(prompt("请输入第一个数："));

        let num2 = parseFloat(prompt("请输入第二个数："));

        alert("两个数的和为：" + (num1 + num2));
      }
    }

    // 100之间所有数之和为
    function calculateSum2() {
      let sum = 0;
      for (let i = 1; i <= 100; i++) {
        sum = sum + i;
      }
      document.write("1-100之间所有数之和为" + sum);
      document.write("</br>");
    }

    // 100之间所有奇数之和为
    function calculateSum3() {
      let sum = 0;
      for (let i = 1; i <= 100; i++) {
        if (i % 2 !== 0) {
          sum = sum + i;
        }
      }
      document.write("1-100之间所有奇数之和为" + sum);
      document.write("</br>");
    }

    // 100之间所有偶数之和为
    function calculateSum4() {
      let sum = 0;
      for (let i = 1; i <= 100; i++) {
        if (i % 2 === 0) {
          sum = sum + i;
        }
      }
      document.write("1-100之间所有偶数之和为" + sum);
      document.write("</br>");
    }

    function calculateSum5(num) {
      let sum = 0;
      for (let i = 1; i <= num; i++) {
        if (i % 2 === 0) {
          sum = sum + i;
        }
      }
      document.write("1-" + num + "之间所有偶数之和为" + sum);
      document.write("</br>");
    }

    // calculateSum1();
    calculateSum2();
    calculateSum3();
    calculateSum4();

    calculateSum5(1000);
  </script>
</body>

</html>